package com.yunxin.core.infra.persistence.repository.product;

import com.yunxin.core.domain.model.product.ProductPromotionInfo;
import com.yunxin.core.domain.model.product.ProductPromotionInfoRepository;
import com.yunxin.core.infra.persistence.converter.ProductConverter;
import com.yunxin.core.infra.persistence.entity.product.ProductPromotionInfoDOWithBLOBs;
import com.yunxin.core.infra.persistence.mapper.product.ProductPromotionInfoExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-13
 */
@Repository
@RequiredArgsConstructor
public class ProductPromotionInfoRepositoryImpl implements ProductPromotionInfoRepository {

    private final ProductPromotionInfoExtendMapper productPromotionInfoExtendMapper;

    private final ProductConverter productConverter;

    @Override
    public boolean saveProductPromotionInfo(ProductPromotionInfo productPromotionInfo) {
        ProductPromotionInfoDOWithBLOBs productPromotionInfoDOWithBLOBs = productConverter.formProductPromotionInfo(productPromotionInfo);
        int count = productPromotionInfoExtendMapper.insertSelective(productPromotionInfoDOWithBLOBs);
        return count > 0;
    }

    @Override
    public boolean updateProductPromotionInfo(ProductPromotionInfo productPromotionInfo) {
        ProductPromotionInfoDOWithBLOBs productPromotionInfoDOWithBLOBs = productConverter.formProductPromotionInfo(productPromotionInfo);
        int count = productPromotionInfoExtendMapper.updateByProductIdSelective(productPromotionInfoDOWithBLOBs);
        return count > 0;
    }
}
